﻿<?php
require_once "Smtp.class.php";
require_once "../../php/config/database.php";
require_once "../user/userDb.php";
require_once "../admin/adminDb.php";
$UserDb=new UserDb();
$adminDb=new AdminDb();
$user=$_POST['userA'];
$data=$UserDb->selectUser($user);
$emailAddress=$data[0]['email'];
$admin=$data[0]['admin'];
$dataAdmin=$adminDb->queryEmail($admin);
$adminEmail=$dataAdmin[0]['email'];
$adminCode=$dataAdmin[0]['emailCode'];

if($emailAddress===""){
    $dat = array(
        'message' =>"对不起，邮件发送失败！请检查邮箱填写是否有误。",
    );
    echo json_encode($dat);
}
else {
    $task_content = $_POST['task_content'];
    $admin = $_POST['user'];
    $task_a = $_POST['task_a'];
    $date = $_POST['date'];
    $remarks = $_POST['remarks'];
    $addtime = date("Y-m-d", time());

//******************** 配置信息 ********************************
    $smtpserver = "ssl://smtp.qq.com";//SMTP服务器
    $smtpserverport = 465;//SMTP服务器端口
    $smtpusermail = $adminEmail;//SMTP服务器的用户邮箱
    $smtpemailto = $emailAddress;//发送给谁
    $smtpuser = $adminEmail;//SMTP服务器的用户帐号，注：部分邮箱只需@前面的用户名
    $smtppass = $adminCode;//SMTP服务器的用户密码
    $mailtitle = "任务通知";//邮件主题
    $mailcontent = "您好：.$user.<a href='http://jishubu.xyz' style='text-decoration: none'>详情请访问：软件分院新青年媒体中心<br></a>" . "<a style='font-size: 20px'>任务:</a><a style='color: red;font-size: 9px;float: right'>发布时间：.$addtime.&nbsp;&nbsp;截至时间：.$date.</a><hr>" . "<h4>" . "<a >任务详情：</a>" . $task_content . "</h4>" . "任务：.$task_a.<br>" . "备注：.$remarks.<hr>" . "<a id='' >发件人：.$admin.</a>";//邮件内容
    $mailtype = "HTML";//邮件格式（HTML/TXT）,TXT为文本邮件
//************************ 配置信息 ****************************
    $smtp = new Smtp($smtpserver, $smtpserverport, true, $smtpuser, $smtppass);//这里面的一个true是表示使用身份验证,否则不使用身份验证.
    $smtp->debug = false;//是否显示发送的调试信息
    $state = $smtp->sendmail($smtpemailto, $smtpusermail, $mailtitle, $mailcontent, $mailtype);

    try {

        if ($state == "") {
            $dat = array(
                'message' => "对不起，邮件发送失败！请检查邮箱填写是否有误。",
            );
            echo json_encode($dat);

        } else {
            $dat = array(
                'message' => "恭喜！邮件发送成功",

            );
            echo json_encode($dat);

        }
    } catch (Exception $e) {
        echo $e->getMessage();

    }
}